//iframe monitor
function iframemonitor()
{
	try{
	//monitoring iframe height
	  var iframe=document.getElementById("frmright");
	  var parentiframeheight=iframe.height;
	  var iframeheight=Math.max(iframe.contentWindow.document.documentElement.scrollHeight,iframe.contentWindow.document.body.scrollHeight);
	  if(parentiframeheight<iframeheight){
		  iframe.height=iframeheight;
	  }
	  else if(parentiframeheight>iframeheight)
	  {
		  if(iframeheight<465) 
			  iframe.height=465;
		  else
			  iframe.height=iframeheight;
	  }
	  
	//monitoring iframe theme
	/*	var parenttheme=document.getElementById('theme').href.split('/');
		  parenttheme=parenttheme[parenttheme.length-2];
	  var iframetheme=iframe.contentWindow.document.getElementById('theme');
		  iframetheme.href='../../skins/theme/'+parenttheme+'/module.css';*/
	  window.setTimeout(iframemonitor,100);
	}catch(e){}
}
  
//clock		
function startTime()   
{   
	  var today=new Date()   
	  var years=today.getFullYear();   
	  var months=today.getMonth();   
	  var d=today.getDate()   
	  var h=today.getHours()   
	  var m=today.getMinutes()   
	  var s=today.getSeconds()   
	  // add a zero in front of numbers<10  
	  monthsmonths=months+1   
	  months=checkTime(months)   
	  d=checkTime(d)   
	  m=checkTime(m)   
	  s=checkTime(s)   
	  var weekday=new Array(7)   
	  weekday[0]="星期日"   
	  weekday[1]="星期一"   
	  weekday[2]=" 星期二"   
	  weekday[3]="星期三"   
	  weekday[4]="星期四"   
	  weekday[5]="星期五"   
	  weekday[6]=" 星期六"   
	  var w=weekday[today.getDay()]   
	  document.getElementById('datepaniel').innerHTML=years+" 年"+months+"月"+d+"日 "+w+" "+h+":"+m+":"+s;   
	  t=setTimeout('startTime()',1000)   
	  }   
	  function checkTime(i)   
	  {   
	  if (i<10)   
	  {i="0" + i}   
	  return i   
} 		

//loadmenu
function loadmenu()
{
	var menusData=MenusData;
	
	var parentTemplate = "";
	$.ajax({type:"get",
	url:"skins/template/menus/parent.html",
	async :false,
	success:function(data){
		parentTemplate = data;
		}   
	});
	
	var childTemplate = "";
	$.ajax({type:"get",
	url:"skins/template/menus/clild.html",
	async :false,
	success:function(msg){
		childTemplate = msg;
		}   
	});		
	
	var topMenusData="",leftMenusData="";
	for(var i=0;i<menusData.length;i++)
	{
		  var menuData=menusData[i];
		  topMenusData+=makeTopmenu(parentTemplate,menuData[0],i,menusData.length);	//生成主菜单
		  leftMenusData+=makeLeftmenu(childTemplate,menuData[1],i);					//生成子菜单
	}
  
	$('#topMenudataPaniel').html(topMenusData);
	$('#leftmenupaniel').html(leftMenusData);
	
	//#支持函数
	function makeTopmenu(template,data,orderid,count)
	{
		  template=template.replace(/\$\{href\}/ig,data.href);
		  template=template.replace(/\$\{label\}/ig,data.label);
		  template=template.replace(/\$\{orderid\}/ig,orderid);				
		  template=template.replace(/\$\{count\}/ig,count);		
		  return template;
	}
	
	function makeLeftmenu(template,data,orderid)
	{
		var insideTemplate=template.match(/<div[^>]*>\s*(<div[^>]*>[\s\S]*<\/div>)\s*<\/div>/)[1];
		var outsideTemplate=template.replace(/(<div[^>]*>\s*)(<div[^>]*>[\s\S]*<\/div>)(\s*<\/div>)/,"$1$tempInsidetemplate$3");
			if(orderid==0){
			  outsideTemplate=outsideTemplate.replace(/\$\{display\}/ig,"");
			}
			else{
			  outsideTemplate=outsideTemplate.replace(/\$\{display\}/ig,"none");
			}
			outsideTemplate=outsideTemplate.replace(/\$\{orderid\}/ig,orderid);

		var tempInsidetemplate="";
		for(var j=0;j<data.length;j++)
		{
			  var tempTemplate=insideTemplate;
			  tempTemplate=tempTemplate.replace(/\$\{href\}/ig,data[j].href);
			  tempTemplate=tempTemplate.replace(/\$\{label\}/ig,data[j].label);
			  tempTemplate=tempTemplate.replace(/\$\{orderid\}/ig,orderid);	
			  tempInsidetemplate+=tempTemplate;		  
		}
		return outsideTemplate.replace(/\$tempInsidetemplate/g,tempInsidetemplate);
	}
}

//switch menu
function disp(n,count)
{
	for (var i=0;i<count;i++)
	{
		if (!document.getElementById("leftmenu_"+i)) return;			
		document.getElementById("leftmenu_"+i).style.display='none';
	}	
	document.getElementById("leftmenu_"+n).style.display='';  
}	